/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package com.cea.papyrus.diagraminterchange2.di2.provider;

import com.cea.papyrus.diagraminterchange2.di2.util.Di2AdapterFactory;

import java.util.ArrayList;
import java.util.Collection;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;

import org.eclipse.emf.edit.provider.ChangeNotifier;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.provider.IChangeNotifier;
import org.eclipse.emf.edit.provider.IDisposable;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertySource;
import org.eclipse.emf.edit.provider.INotifyChangedListener;
import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
import org.eclipse.emf.edit.provider.ITreeItemContentProvider;

/**
 * This is the factory that is used to provide the interfaces needed to support Viewers.
 * The adapters generated by this factory convert EMF adapter notifications into calls to {@link #fireNotifyChanged fireNotifyChanged}.
 * The adapters also support Eclipse property sheets.
 * Note that most of the adapters are shared among multiple instances.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public class Di2ItemProviderAdapterFactory extends Di2AdapterFactory implements ComposeableAdapterFactory, IChangeNotifier, IDisposable {
	/**
	 * This keeps track of the root adapter factory that delegates to this adapter factory.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ComposedAdapterFactory parentAdapterFactory;

	/**
	 * This is used to implement {@link org.eclipse.emf.edit.provider.IChangeNotifier}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected IChangeNotifier changeNotifier = new ChangeNotifier();

	/**
	 * This keeps track of all the supported types checked by {@link #isFactoryForType isFactoryForType}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected Collection<Object> supportedTypes = new ArrayList<Object>();

	/**
	 * This constructs an instance.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Di2ItemProviderAdapterFactory() {
		supportedTypes.add(IEditingDomainItemProvider.class);
		supportedTypes.add(IStructuredItemContentProvider.class);
		supportedTypes.add(ITreeItemContentProvider.class);
		supportedTypes.add(IItemLabelProvider.class);
		supportedTypes.add(IItemPropertySource.class);
	}

	/**
	 * This keeps track of the one adapter used for all {@link com.cea.papyrus.diagraminterchange2.di2.DiagramElement} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected DiagramElementItemProvider diagramElementItemProvider;

	/**
	 * This creates an adapter for a {@link com.cea.papyrus.diagraminterchange2.di2.DiagramElement}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createDiagramElementAdapter() {
		if (diagramElementItemProvider == null) {
			diagramElementItemProvider = new DiagramElementItemProvider(this);
		}

		return diagramElementItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link com.cea.papyrus.diagraminterchange2.di2.GraphElement} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected GraphElementItemProvider graphElementItemProvider;

	/**
	 * This creates an adapter for a {@link com.cea.papyrus.diagraminterchange2.di2.GraphElement}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createGraphElementAdapter() {
		if (graphElementItemProvider == null) {
			graphElementItemProvider = new GraphElementItemProvider(this);
		}

		return graphElementItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link com.cea.papyrus.diagraminterchange2.di2.Reference} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ReferenceItemProvider referenceItemProvider;

	/**
	 * This creates an adapter for a {@link com.cea.papyrus.diagraminterchange2.di2.Reference}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createReferenceAdapter() {
		if (referenceItemProvider == null) {
			referenceItemProvider = new ReferenceItemProvider(this);
		}

		return referenceItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link com.cea.papyrus.diagraminterchange2.di2.Property} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected PropertyItemProvider propertyItemProvider;

	/**
	 * This creates an adapter for a {@link com.cea.papyrus.diagraminterchange2.di2.Property}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createPropertyAdapter() {
		if (propertyItemProvider == null) {
			propertyItemProvider = new PropertyItemProvider(this);
		}

		return propertyItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link com.cea.papyrus.diagraminterchange2.di2.GraphEdge} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected GraphEdgeItemProvider graphEdgeItemProvider;

	/**
	 * This creates an adapter for a {@link com.cea.papyrus.diagraminterchange2.di2.GraphEdge}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createGraphEdgeAdapter() {
		if (graphEdgeItemProvider == null) {
			graphEdgeItemProvider = new GraphEdgeItemProvider(this);
		}

		return graphEdgeItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link com.cea.papyrus.diagraminterchange2.di2.GraphConnector} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected GraphConnectorItemProvider graphConnectorItemProvider;

	/**
	 * This creates an adapter for a {@link com.cea.papyrus.diagraminterchange2.di2.GraphConnector}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createGraphConnectorAdapter() {
		if (graphConnectorItemProvider == null) {
			graphConnectorItemProvider = new GraphConnectorItemProvider(this);
		}

		return graphConnectorItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link com.cea.papyrus.diagraminterchange2.di2.GraphNode} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected GraphNodeItemProvider graphNodeItemProvider;

	/**
	 * This creates an adapter for a {@link com.cea.papyrus.diagraminterchange2.di2.GraphNode}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createGraphNodeAdapter() {
		if (graphNodeItemProvider == null) {
			graphNodeItemProvider = new GraphNodeItemProvider(this);
		}

		return graphNodeItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link com.cea.papyrus.diagraminterchange2.di2.DiagramLink} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected DiagramLinkItemProvider diagramLinkItemProvider;

	/**
	 * This creates an adapter for a {@link com.cea.papyrus.diagraminterchange2.di2.DiagramLink}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createDiagramLinkAdapter() {
		if (diagramLinkItemProvider == null) {
			diagramLinkItemProvider = new DiagramLinkItemProvider(this);
		}

		return diagramLinkItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link com.cea.papyrus.diagraminterchange2.di2.Diagram} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected DiagramItemProvider diagramItemProvider;

	/**
	 * This creates an adapter for a {@link com.cea.papyrus.diagraminterchange2.di2.Diagram}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createDiagramAdapter() {
		if (diagramItemProvider == null) {
			diagramItemProvider = new DiagramItemProvider(this);
		}

		return diagramItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link com.cea.papyrus.diagraminterchange2.di2.SemanticModelBridge} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected SemanticModelBridgeItemProvider semanticModelBridgeItemProvider;

	/**
	 * This creates an adapter for a {@link com.cea.papyrus.diagraminterchange2.di2.SemanticModelBridge}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createSemanticModelBridgeAdapter() {
		if (semanticModelBridgeItemProvider == null) {
			semanticModelBridgeItemProvider = new SemanticModelBridgeItemProvider(this);
		}

		return semanticModelBridgeItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link com.cea.papyrus.diagraminterchange2.di2.SimpleSemanticModelElement} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected SimpleSemanticModelElementItemProvider simpleSemanticModelElementItemProvider;

	/**
	 * This creates an adapter for a {@link com.cea.papyrus.diagraminterchange2.di2.SimpleSemanticModelElement}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createSimpleSemanticModelElementAdapter() {
		if (simpleSemanticModelElementItemProvider == null) {
			simpleSemanticModelElementItemProvider = new SimpleSemanticModelElementItemProvider(this);
		}

		return simpleSemanticModelElementItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link com.cea.papyrus.diagraminterchange2.di2.Uml1SemanticModelBridge} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected Uml1SemanticModelBridgeItemProvider uml1SemanticModelBridgeItemProvider;

	/**
	 * This creates an adapter for a {@link com.cea.papyrus.diagraminterchange2.di2.Uml1SemanticModelBridge}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createUml1SemanticModelBridgeAdapter() {
		if (uml1SemanticModelBridgeItemProvider == null) {
			uml1SemanticModelBridgeItemProvider = new Uml1SemanticModelBridgeItemProvider(this);
		}

		return uml1SemanticModelBridgeItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link com.cea.papyrus.diagraminterchange2.di2.CoreSemanticModelBridge} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected CoreSemanticModelBridgeItemProvider coreSemanticModelBridgeItemProvider;

	/**
	 * This creates an adapter for a {@link com.cea.papyrus.diagraminterchange2.di2.CoreSemanticModelBridge}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createCoreSemanticModelBridgeAdapter() {
		if (coreSemanticModelBridgeItemProvider == null) {
			coreSemanticModelBridgeItemProvider = new CoreSemanticModelBridgeItemProvider(this);
		}

		return coreSemanticModelBridgeItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link com.cea.papyrus.diagraminterchange2.di2.LeafElement} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected LeafElementItemProvider leafElementItemProvider;

	/**
	 * This creates an adapter for a {@link com.cea.papyrus.diagraminterchange2.di2.LeafElement}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createLeafElementAdapter() {
		if (leafElementItemProvider == null) {
			leafElementItemProvider = new LeafElementItemProvider(this);
		}

		return leafElementItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link com.cea.papyrus.diagraminterchange2.di2.TextElement} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected TextElementItemProvider textElementItemProvider;

	/**
	 * This creates an adapter for a {@link com.cea.papyrus.diagraminterchange2.di2.TextElement}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createTextElementAdapter() {
		if (textElementItemProvider == null) {
			textElementItemProvider = new TextElementItemProvider(this);
		}

		return textElementItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link com.cea.papyrus.diagraminterchange2.di2.Image} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ImageItemProvider imageItemProvider;

	/**
	 * This creates an adapter for a {@link com.cea.papyrus.diagraminterchange2.di2.Image}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createImageAdapter() {
		if (imageItemProvider == null) {
			imageItemProvider = new ImageItemProvider(this);
		}

		return imageItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link com.cea.papyrus.diagraminterchange2.di2.GraphicPrimitive} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected GraphicPrimitiveItemProvider graphicPrimitiveItemProvider;

	/**
	 * This creates an adapter for a {@link com.cea.papyrus.diagraminterchange2.di2.GraphicPrimitive}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createGraphicPrimitiveAdapter() {
		if (graphicPrimitiveItemProvider == null) {
			graphicPrimitiveItemProvider = new GraphicPrimitiveItemProvider(this);
		}

		return graphicPrimitiveItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link com.cea.papyrus.diagraminterchange2.di2.Polilyne} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected PolilyneItemProvider polilyneItemProvider;

	/**
	 * This creates an adapter for a {@link com.cea.papyrus.diagraminterchange2.di2.Polilyne}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createPolilyneAdapter() {
		if (polilyneItemProvider == null) {
			polilyneItemProvider = new PolilyneItemProvider(this);
		}

		return polilyneItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link com.cea.papyrus.diagraminterchange2.di2.Ellipse} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected EllipseItemProvider ellipseItemProvider;

	/**
	 * This creates an adapter for a {@link com.cea.papyrus.diagraminterchange2.di2.Ellipse}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createEllipseAdapter() {
		if (ellipseItemProvider == null) {
			ellipseItemProvider = new EllipseItemProvider(this);
		}

		return ellipseItemProvider;
	}

	/**
	 * This returns the root adapter factory that contains this factory.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ComposeableAdapterFactory getRootAdapterFactory() {
		return parentAdapterFactory == null ? this : parentAdapterFactory.getRootAdapterFactory();
	}

	/**
	 * This sets the composed adapter factory that contains this factory.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setParentAdapterFactory(ComposedAdapterFactory parentAdapterFactory) {
		this.parentAdapterFactory = parentAdapterFactory;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean isFactoryForType(Object type) {
		return supportedTypes.contains(type) || super.isFactoryForType(type);
	}

	/**
	 * This implementation substitutes the factory itself as the key for the adapter.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter adapt(Notifier notifier, Object type) {
		return super.adapt(notifier, this);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object adapt(Object object, Object type) {
		if (isFactoryForType(type)) {
			Object adapter = super.adapt(object, type);
			if (!(type instanceof Class) || (((Class<?>)type).isInstance(adapter))) {
				return adapter;
			}
		}

		return null;
	}

	/**
	 * This adds a listener.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void addListener(INotifyChangedListener notifyChangedListener) {
		changeNotifier.addListener(notifyChangedListener);
	}

	/**
	 * This removes a listener.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void removeListener(INotifyChangedListener notifyChangedListener) {
		changeNotifier.removeListener(notifyChangedListener);
	}

	/**
	 * This delegates to {@link #changeNotifier} and to {@link #parentAdapterFactory}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void fireNotifyChanged(Notification notification) {
		changeNotifier.fireNotifyChanged(notification);

		if (parentAdapterFactory != null) {
			parentAdapterFactory.fireNotifyChanged(notification);
		}
	}

	/**
	 * This disposes all of the item providers created by this factory. 
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void dispose() {
		if (diagramElementItemProvider != null) diagramElementItemProvider.dispose();
		if (graphElementItemProvider != null) graphElementItemProvider.dispose();
		if (referenceItemProvider != null) referenceItemProvider.dispose();
		if (propertyItemProvider != null) propertyItemProvider.dispose();
		if (graphEdgeItemProvider != null) graphEdgeItemProvider.dispose();
		if (graphConnectorItemProvider != null) graphConnectorItemProvider.dispose();
		if (graphNodeItemProvider != null) graphNodeItemProvider.dispose();
		if (diagramLinkItemProvider != null) diagramLinkItemProvider.dispose();
		if (diagramItemProvider != null) diagramItemProvider.dispose();
		if (semanticModelBridgeItemProvider != null) semanticModelBridgeItemProvider.dispose();
		if (simpleSemanticModelElementItemProvider != null) simpleSemanticModelElementItemProvider.dispose();
		if (uml1SemanticModelBridgeItemProvider != null) uml1SemanticModelBridgeItemProvider.dispose();
		if (coreSemanticModelBridgeItemProvider != null) coreSemanticModelBridgeItemProvider.dispose();
		if (leafElementItemProvider != null) leafElementItemProvider.dispose();
		if (textElementItemProvider != null) textElementItemProvider.dispose();
		if (imageItemProvider != null) imageItemProvider.dispose();
		if (graphicPrimitiveItemProvider != null) graphicPrimitiveItemProvider.dispose();
		if (polilyneItemProvider != null) polilyneItemProvider.dispose();
		if (ellipseItemProvider != null) ellipseItemProvider.dispose();
	}

}
